package palmtop.com.palmtop.fragment;

import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import android.support.v7.widget.GridLayout;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import net.grandcentrix.tray.AppPreferences;

import org.xutils.common.Callback;
import org.xutils.http.RequestParams;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Timer;
import java.util.TimerTask;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import palmtop.com.palmtop.R;
import palmtop.com.palmtop.activity.AddClueActivity;
import palmtop.com.palmtop.activity.AddPopulationActivity;
import palmtop.com.palmtop.activity.ClueAcountActivity;
import palmtop.com.palmtop.activity.ClueActivity;
import palmtop.com.palmtop.activity.ClueListActivity;
import palmtop.com.palmtop.activity.DistributeActivity;
import palmtop.com.palmtop.activity.DistributeGridActivity;
import palmtop.com.palmtop.activity.HisgridtaskActivity;
import palmtop.com.palmtop.activity.HistaskActivity;
import palmtop.com.palmtop.activity.InfodetailActivity;
import palmtop.com.palmtop.activity.KaoheActivity;
import palmtop.com.palmtop.activity.MainActivity;
import palmtop.com.palmtop.activity.MapActivity;
import palmtop.com.palmtop.activity.MytaskActivity;
import palmtop.com.palmtop.activity.PopulationActivity;
import palmtop.com.palmtop.activity.PopulationListActivity;
import palmtop.com.palmtop.activity.PopulationacountActivity;
import palmtop.com.palmtop.activity.WaittaskActivity;
import palmtop.com.palmtop.adapter.GalleryIndexSecondAdapter;
import palmtop.com.palmtop.model.Clue;
import palmtop.com.palmtop.model.InfoDissemina;
import palmtop.com.palmtop.model.Reportpopulation;
import palmtop.com.palmtop.model.RoleMenu;
import palmtop.com.palmtop.model.Taskcount;
import palmtop.com.palmtop.model.Unit;
import palmtop.com.palmtop.util.BadgeView;
import palmtop.com.palmtop.util.Config;
import palmtop.com.palmtop.util.DetailGallery;
import palmtop.com.palmtop.util.NetUtil;
import palmtop.com.palmtop.util.ToastUtil;
import palmtop.com.palmtop.util.Tool;


public class MainFragment extends Fragment  {


    @BindView(R.id.myGallery)
    DetailGallery myGallery;
    @BindView(R.id.galleryRaidoGroup)
    RadioGroup galleryRaidoGroup;
    @BindView(R.id.downtaskBtn)
    ImageButton downtaskBtn;
    @BindView(R.id.distaskLayout)
    LinearLayout distaskLayout;
    @BindView(R.id.waittaskBtn)
    ImageButton waittaskBtn;
    @BindView(R.id.waittaskLayout)
    LinearLayout waittaskLayout;
    @BindView(R.id.histaskBtn)
    ImageButton histaskBtn;
    @BindView(R.id.histaskLayout)
    LinearLayout histaskLayout;
    @BindView(R.id.populationBtn)
    ImageButton populationBtn;
    @BindView(R.id.populationLayout)
    LinearLayout populationLayout;
    @BindView(R.id.clueBtn)
    ImageButton clueBtn;
    @BindView(R.id.cluelistLayout)
    LinearLayout cluelistLayout;
    @BindView(R.id.mapBtn)
    ImageButton mapBtn;
    @BindView(R.id.mapLayout)
    LinearLayout mapLayout;
    @BindView(R.id.kaoheBtn)
    ImageButton kaoheBtn;
    @BindView(R.id.kaoheLayout)
    LinearLayout kaoheLayout;
    @BindView(R.id.mytaskBtn)
    ImageButton mytaskBtn;
    @BindView(R.id.mytaskLayout)
    LinearLayout mytaskLayout;
    @BindView(R.id.addpopulationBtn)
    ImageButton addpopulationBtn;
    @BindView(R.id.addpopulationLayout)
    LinearLayout addpopulationLayout;
    @BindView(R.id.addclueBtn)
    ImageButton addclueBtn;
    @BindView(R.id.addclueLayout)
    LinearLayout addclueLayout;
    @BindView(R.id.mygrids)
    GridLayout mygrids;
//    private OnFragmentInteractionListener mListener;
    private Unbinder unbinder;
    private LinearLayout layout;
    ArrayList<String> listaa;
    ArrayList<InfoDissemina> imageList;
    private RadioButton[] gallery_point;
    private RadioGroup gallery_points;
    private LayoutInflater inflaters;

    private long mBackPressed;
    private static final int TIME_INTERVAL = 2000;
    //    private SharedPreferences sharedPreferences;
    String permission;
    //    SharedPreferences permissionPreferences;
    private ArrayList<RoleMenu> arrayList;
    String[] arr;
    String role_id = "";
    String ssgrid = "";
    String userid = "";
    Context context ;
    Timer time;

    public MainFragment() {
        // Required empty public constructor
    }


    public static MainFragment newInstance(String param1, String param2) {
        MainFragment fragment = new MainFragment();
        Bundle args = new Bundle();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
//        return inflater.inflate(R.layout.fragment_main, container, false);
        View view = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_main, null);
        //返回一个Unbinder值（进行解绑），注意这里的this不能使用getActivity()
        unbinder = ButterKnife.bind(this, view);
        inflaters = inflater;
        init(view);
        return view;
    }

    private void init(View view) {
//        myGallery = (DetailGallery)view.findViewById(R.id.myGallery);
        gallery_points = (RadioGroup) view.findViewById(R.id.galleryRaidoGroup);
        context = getActivity();
        addEvn();
        AppPreferences appPreferences = new AppPreferences(getActivity());
        //permission = appPreferences.getString("permission","");
        String username = appPreferences.getString("loginname","");
        userid = appPreferences.getString("userid","");
        role_id = appPreferences.getString("role_id","");
        ssgrid = appPreferences.getString("ssgrid","");
        //permission = appPreferences.getString("permission","");====================================
        permission = "";
        if(permission==null||permission.equals("")){
            //ToastUtil.show(getActivity(),"在这里执行的");
            getPermissionMenu(userid,username);

            if(role_id.equals("d18ac0ef29ee477f8e3dd214245a1de5")){
                getWaitTaskgridcount(ssgrid);
                getHisTaskgridcount(ssgrid);
                getCluecount(ssgrid);
                getPopulationcount(ssgrid);
            }else if(role_id.equals("73006b03b7f447bf953d065462e5b1ac")){
                getHisTaskcount();
                getCluecount();
                getPopulationcount();
            }else{
                getMytaskcount(userid);
            }

        }else{
            showMenu();
            if(role_id.equals("d18ac0ef29ee477f8e3dd214245a1de5")){
                getWaitTaskgridcount(ssgrid);
                getHisTaskgridcount(ssgrid);
            }else{
                getMytaskcount(userid);
            }
        }

        RequestParams para = new RequestParams(Config.SERVER_URL+"infodissemina/getlist");
        NetUtil.postData(para, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                listaa = new ArrayList<String>();
                Gson gson = new Gson();
                Type listtype = new TypeToken<ArrayList<InfoDissemina>>() {
                }.getType();
                imageList = gson.fromJson(result,listtype);
                if(imageList!=null&&imageList.size()>0){
                    for(int a=0;a<imageList.size();a++){
                        String url = Config.IMG_URL+imageList.get(a).getPhoto();
                        // Bitmap bitmap = FuncUtil.getHttpBitmap(url);
                        listaa.add(url);
                    }
                    GalleryIndexSecondAdapter adapter = new GalleryIndexSecondAdapter(listaa,context);
                    myGallery.setAdapter(adapter);
                }

                //设置小按钮
                gallery_point = new RadioButton[listaa.size()];
                for (int i = 0; i < gallery_point.length; i++) {
                    layout = (LinearLayout) inflaters.inflate(R.layout.gallery_icon, null);
                    gallery_point[i] = (RadioButton) layout.findViewById(R.id.gallery_radiobutton);
                    gallery_point[i].setId(i);/* 设置指示图按钮ID */
                    int wh = Tool.px2dp(context, 10);
                    RadioGroup.LayoutParams layoutParams = new RadioGroup.LayoutParams(wh, wh); // 设置指示图大小
                    gallery_point[i].setLayoutParams(layoutParams);
                    layoutParams.setMargins(4, 0, 4, 0);// 设置指示图margin值
                    gallery_point[i].setClickable(false);/* 设置指示图按钮不能点击 */
                    layout.removeView(gallery_point[i]);//一个子视图不能指定了多个父视图
                    gallery_points.addView(gallery_point[i]);/* 把已经初始化的指示图动态添加到指示图的RadioGroup中 */
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {

            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {

            }
        });
    }

    //getPopulationcount
    private void getPopulationcount() {
        RequestParams params = new RequestParams(Config.SERVER_URL + "reportpopulation/getPopulationcount1");
        NetUtil.postData(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                if(!(result==null||result.equals("\"\""))){
                    BadgeView badge = new BadgeView(getActivity(), populationBtn);
                    badge.setText(result);
                    badge.show();
                }
            }
            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
            }
            @Override
            public void onCancelled(CancelledException cex) {
            }
            @Override
            public void onFinished() {
            }
        });
    }

    private void getCluecount() {
        RequestParams params = new RequestParams(Config.SERVER_URL + "clue/getCluecount1");
        NetUtil.postData(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                if(!(result==null||result.equals("\"\""))){
                    BadgeView badge = new BadgeView(getActivity(), clueBtn);
                    badge.setText(result);
                    badge.show();
                }
            }
            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
            }
            @Override
            public void onCancelled(CancelledException cex) {
            }
            @Override
            public void onFinished() {
            }
        });
    }

    private void getCluecount(String ssgrid) {
        RequestParams params = new RequestParams(Config.SERVER_URL + "clue/getCluecount");
        params.addBodyParameter("unitid", ssgrid);
        NetUtil.postData(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                if(!(result==null||result.equals("\"\""))){
                    BadgeView badge = new BadgeView(getActivity(), clueBtn);
                    badge.setText(result);
                    badge.show();
                }
            }
            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
            }
            @Override
            public void onCancelled(CancelledException cex) {
            }
            @Override
            public void onFinished() {
            }
        });
    }

    private void getPopulationcount(String ssgrid) {
        RequestParams params = new RequestParams(Config.SERVER_URL + "reportpopulation/getPopulationcount");
        params.addBodyParameter("unitid", ssgrid);
        NetUtil.postData(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                if(!(result==null||result.equals("\"\""))){
                    BadgeView badge = new BadgeView(getActivity(), populationBtn);
                    badge.setText(result);
                    badge.show();
                }
            }
            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
            }
            @Override
            public void onCancelled(CancelledException cex) {
            }
            @Override
            public void onFinished() {
            }
        });
    }

    //社区民警代办任务
    private void getWaitTaskgridcount(String ssgrid) {
        RequestParams params = new RequestParams(Config.SERVER_URL + "taskgridapp/getWaitTaskgridcount");
        params.addBodyParameter("unitid", ssgrid);
        NetUtil.postData(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                if(!(result==null||result.equals("\"\""))){
                    BadgeView badge = new BadgeView(getActivity(), waittaskBtn);
                    badge.setText(result);
                    badge.show();
                }
            }
            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
            }
            @Override
            public void onCancelled(CancelledException cex) {
            }
            @Override
            public void onFinished() {
            }
        });

    }
    //社区民警历史任务
    private void getHisTaskgridcount(String ssgrid) {
        RequestParams params = new RequestParams(Config.SERVER_URL + "taskgridapp/getHisTaskgridcount");
        params.addBodyParameter("unitid", ssgrid);
        NetUtil.postData(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                if(!(result==null||result.equals("\"\""))){
                    BadgeView badge = new BadgeView(getActivity(), histaskBtn);
                    badge.setText(result);
                    badge.show();

                }
            }
            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
            }
            @Override
            public void onCancelled(CancelledException cex) {
            }
            @Override
            public void onFinished() {
            }
        });

    }
    //我的任务
    private void getMytaskcount(String userid) {
        RequestParams params = new RequestParams(Config.SERVER_URL + "taskgridapp/getMytaskcount");
        params.addBodyParameter("receiverid", userid);
        NetUtil.postData(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                if(!(result==null||result.equals("\"\""))){
                    BadgeView badge = new BadgeView(getActivity(), mytaskBtn);
                    badge.setText(result);
                    badge.show();
                }
            }
            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
            }
            @Override
            public void onCancelled(CancelledException cex) {
            }
            @Override
            public void onFinished() {
            }
        });

    }
    //领导历史任务
    public void getHisTaskcount() {
        RequestParams params = new RequestParams(Config.SERVER_URL + "taskapp/getHisTaskcount");
//        params.addBodyParameter("name", unitname);
        NetUtil.postData(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                if(!(result==null||result.equals("\"\""))){
                    BadgeView badge = new BadgeView(getActivity(), histaskBtn);
                    badge.setText(result);
                    badge.show();
                }
            }
            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
            }
            @Override
            public void onCancelled(CancelledException cex) {
            }
            @Override
            public void onFinished() {
            }
        });
    }


    public void getPermissionMenu(String userid,String username){
        RequestParams params = new RequestParams(Config.SERVER_URL+"sys/loginapi/getmenu");
        params.addBodyParameter("userid",userid);
        params.addBodyParameter("username",username);
        NetUtil.postData(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                Gson gson = new Gson();
                Type listType = new TypeToken<ArrayList<RoleMenu>>(){}.getType();
                arrayList = gson.fromJson(result,listType);
                StringBuilder builder = new StringBuilder();
                if(arrayList.size()>0){
                    for (int i = 0;i<arrayList.size();i++){
                        builder.append(arrayList.get(i).getMenuId());
                        builder.append(",");
                    }
                }
                if(builder.lastIndexOf(",")!=-1){
                    builder.deleteCharAt(builder.lastIndexOf(","));
                }
                permission = builder.toString();
//                SharedPreferences.Editor editor = permissionPreferences.edit();
//                editor.putString("permission", permission);
//                editor.commit();
                AppPreferences appPreferences = new AppPreferences(getActivity());
                appPreferences.put("permission",permission);
                //showMenu();
                //ToastUtil.show(LoginActivity.this,"permissions--->"+permission);
                if(permission!=null&&!permission.equals("")){
                    arr = permission.split(",");
                    // HashMap<String,Integer> permissionmap = FuncUtil.permissionMap;
                    HashMap<String,Integer> permissionmap = new HashMap<String,Integer>(){
                        {
                            put("44902f477395472d9494ee1309bb762a",R.id.distaskLayout);//任务下发
                            put("1eacf7913b204ad089a02dce0885827f",R.id.waittaskLayout);//代办任务
                            put("9a46dc829acb4915895f1366e610ab4c",R.id.histaskLayout);//历史任务
                            put("a408b4147d5540afa5786ef68b038231",R.id.populationLayout);//人口管理
                            put("954cc599ab524022859e3f5bff1325ff",R.id.cluelistLayout);//线索搜集
                            put("b98d4c9ef5f84286afb515074428f28e",R.id.mapLayout);//人员位置
                            put("f566cb1e1ccc411d9cd8a5f3c35a10d0",R.id.kaoheLayout);//人员考核
                            put("52b141ebc5c84781b7a40dd6b018ea4d",R.id.mytaskLayout);//我的任务
                            put("73727620627f4578b5660ede85afeb39",R.id.addpopulationLayout);// 人口上报
                            put("3ca31dd936e44759b957e05fde01b892",R.id.addclueLayout);// 线索上报
                        }
                    };

                    if(arr.length>0){
                        for(int i=0;i<arrayList.size();i++){
                            if(permissionmap.containsKey(arrayList.get(i).getMenuId())){
                                //permissionmap.get(arr[i]);
                                permissionmap.remove(arrayList.get(i).getMenuId());
                            }
                        }
                        for(String key : permissionmap.keySet()){
                            if(permissionmap.get(key)!=null){
                                View view = getActivity().findViewById(permissionmap.get(key));
                                if(view!=null){
                                    view.setVisibility(View.GONE);
                                    //View views = getActivity().findViewById(permissionmap.get(key));
                                    mygrids.removeView(view);
                                }

                            }
                        }
                    }
                }else{
                    ToastUtil.show(getActivity(),"未获取权限列表");
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {

            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {

            }
        });
    }


    private void showMenu(){
        if(permission!=null&&!permission.equals("")){
            arr = permission.split(",");
            //HashMap<String,Integer> permissionmap = FuncUtil.permissionMap;
            HashMap<String,Integer> permissionmap = new HashMap<String,Integer>(){
                {
                    put("44902f477395472d9494ee1309bb762a",R.id.distaskLayout);//任务下发
                    put("1eacf7913b204ad089a02dce0885827f",R.id.waittaskLayout);//代办任务
                    put("9a46dc829acb4915895f1366e610ab4c",R.id.histaskLayout);//历史任务
                    put("a408b4147d5540afa5786ef68b038231",R.id.populationLayout);//人口管理
                    put("954cc599ab524022859e3f5bff1325ff",R.id.cluelistLayout);//线索搜集
                    put("b98d4c9ef5f84286afb515074428f28e",R.id.mapLayout);//人员位置
                    put("f566cb1e1ccc411d9cd8a5f3c35a10d0",R.id.kaoheLayout);//人员考核
                    put("52b141ebc5c84781b7a40dd6b018ea4d",R.id.mytaskLayout);//我的任务
                    put("73727620627f4578b5660ede85afeb39",R.id.addpopulationLayout);// 人口上报
                    put("3ca31dd936e44759b957e05fde01b892",R.id.addclueLayout);// 线索上报
                }
            };

            if(arr.length>0){
                for(int i=0;i<arr.length;i++){
                    if(permissionmap.containsKey(arr[i])){
                        //permissionmap.get(arr[i]);
                        permissionmap.remove(arr[i]);
                    }
                }
                for(String key : permissionmap.keySet()){
                    if(permissionmap.get(key)!=null){
                        View view = getActivity().findViewById(permissionmap.get(key));
                        if(view!=null){
                            view.setVisibility(View.GONE);
                            View views = getActivity().findViewById(permissionmap.get(key));
                            mygrids.removeView(views);
                        }

                    }
                }
            }
        }else{
            ToastUtil.show(getActivity(),"未获取权限列表11");
        }
    }



    @OnClick(R.id.downtaskBtn)
    public void onDowntaskBtnClicked() {
        Intent i = new Intent();
        if(role_id.equals("73006b03b7f447bf953d065462e5b1ac")){
            i.setClass(getActivity(), DistributeActivity.class);
        }else{
            i.setClass(getActivity(), DistributeGridActivity.class);
        }

        startActivity(i);
    }

    @OnClick(R.id.waittaskBtn)
    public void onWaittaskBtnClicked() {
        Intent i = new Intent();
        i.setClass(getActivity(), WaittaskActivity.class);
        startActivity(i);
    }



    @OnClick(R.id.histaskBtn)
    public void onHistaskBtnClicked() {
        Intent i = new Intent();
        if(role_id.equals("73006b03b7f447bf953d065462e5b1ac")){
            i.setClass(getActivity(), HistaskActivity.class);
        }else{
            i.setClass(getActivity(), HisgridtaskActivity.class);
        }

        startActivity(i);
    }

    @OnClick(R.id.populationBtn)
    public void onPopulationBtnClicked() {
        Intent i = new Intent();
        if(role_id.equals("73006b03b7f447bf953d065462e5b1ac")){
            i.setClass(getActivity(), PopulationacountActivity.class);
        }else{
            Reportpopulation reportpopulation = new Reportpopulation();
            reportpopulation.setUnitid(Integer.valueOf(ssgrid));
            i.putExtra("reportpopulation",reportpopulation);
            i.setClass(getActivity(), PopulationActivity.class);
        }

        startActivity(i);
    }

    @OnClick(R.id.clueBtn)
    public void onClueBtnClicked() {
        Intent i = new Intent();

        if(role_id.equals("73006b03b7f447bf953d065462e5b1ac")){
            i.setClass(getActivity(), ClueAcountActivity.class);
        }else{
            Clue clue = new Clue();
            clue.setUnitid(ssgrid);
            i.putExtra("clue",clue);
            i.setClass(getActivity(), ClueActivity.class);
        }
        startActivity(i);
    }
    //人员位置
    @OnClick(R.id.mapBtn)
    public void onMapBtnClicked() {
        Intent i = new Intent();
        i.setClass(getActivity(), MapActivity.class);
        startActivity(i);
    }
    //人员考核
    @OnClick(R.id.kaoheBtn)
    public void onKaoheBtnClicked() {
        Intent i = new Intent();
        i.setClass(getActivity(), KaoheActivity.class);
        startActivity(i);
    }

    @OnClick(R.id.mytaskBtn)
    public void onMytaskBtnClicked() {
        Intent i = new Intent();
        i.setClass(getActivity(), MytaskActivity.class);
        startActivity(i);
    }

    @OnClick(R.id.addpopulationBtn)
    public void onAddpopulationClicked() {
        Intent i = new Intent();
        i.setClass(getActivity(), PopulationListActivity.class);
        startActivity(i);
    }

    @OnClick(R.id.addclueBtn)
    public void onAddClueClicked() {
        Intent i = new Intent();
        i.setClass(getActivity(), ClueListActivity.class);
        startActivity(i);
    }



    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
/*

    public void onButtonPressed(Uri uri) {
        if (mListener != null) {
            mListener.onFragmentInteraction(uri);
        }
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        if (context instanceof OnFragmentInteractionListener) {
            mListener = (OnFragmentInteractionListener) context;
        } else {
            throw new RuntimeException(context.toString()
                    + " must implement OnFragmentInteractionListener");
        }
    }

    @Override
    public void onDetach() {
        super.onDetach();
        mListener = null;
    }
*/




    public interface OnFragmentInteractionListener {
        // TODO: Update argument type and name
        void onFragmentInteraction(Uri uri);
    }
/*
    @Override
    public void onFragmentInteraction(Uri uri) {

    }*/

    void addEvn(){
        myGallery.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                // TODO Auto-generated method stub
                gallery_points.check(gallery_point[arg2%gallery_point.length].getId());
            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0) {
                // TODO Auto-generated method stub
            }
        });
        myGallery.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                startActivity(new Intent(context, InfodetailActivity.class).putExtra("info",imageList.get(position%3)));
            }
        });
    }

    final Handler handler_gallery = new Handler() {
        public void handleMessage(Message msg) {
			/* 自定义屏幕按下的动作 */
            MotionEvent e1 = MotionEvent.obtain(SystemClock.uptimeMillis(),
                    SystemClock.uptimeMillis(), MotionEvent.ACTION_UP,
                    89.333336f, 265.33334f, 0);
			/* 自定义屏幕放开的动作 */
            MotionEvent e2 = MotionEvent.obtain(SystemClock.uptimeMillis(),
                    SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN,
                    300.0f, 238.00003f, 0);

            myGallery.onFling(e2, e1, -800, 0);
			/* 给gallery添加按下和放开的动作，实现自动滑动 */
            super.handleMessage(msg);
        }
    };
    public void onResume() {
        if(time!=null){
            time.cancel();
        }
        autogallery();
        super.onResume();
    }

    @Override
    public void onPause() {
        if(time!=null){
            time.cancel();
        }
        super.onPause();

    }

    ;
    private void autogallery() {
		/* 设置定时器，每5秒自动切换展示图 */
        //Timer time = ProjectConfig.TimerInstance;
        time = new Timer();
        TimerTask task = new TimerTask() {
            @Override
            public void run() {
                Message m = new Message();
                handler_gallery.sendMessage(m);
            }
        };
        //time.schedule(task, 8000, 5000);
        //time.schedule(task, 8000,7000);
        time.schedule(task,8000,5000);
    }
}
